<!DOCTYPE html>
<html lang="zc-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        let userInfo = {
  token1: {
    city: '杭州',
    money: '1000w',
    sex: '女',
    userName: 'admin',
    password: 'admin321'
  },
  token2: {
    city: '北京',
    money: '1100w',
    sex: '女',
    userName: 'zhangsan',
    password: 'zs321'
  },
  token3: {
    city: '北京',
    money: '800w',
    sex: '男',
    userName: 'lisi', 
    password: 'ls321'
  },
  token4: {
    city: '天津',
    money: '600w',
    sex: '男',
    userName: 'yyqx',
    password: 'yyqx321'
  }
}
        let loginList = [ 
  {userName: 'admin', password: 'admin321'},
  {userName: 'zhangsan', password: 'zs321'},
  {userName: 'lisi', password: 'ls321'},
  {userName: 'yyqx', password: 'yyqx321'}
]

            function getLogin (loginList) {
              for(;;) {
              let username = prompt('请输入用户名')
              let password = prompt('请输入密码')
                for (let k=0;k<loginList.length;k++) {
                    if (username ===loginList[k].userName && password ===loginList[k].password) {
                        alert('登录成功')
                        let token = 0
                        let i =Math.floor(Math.random()*4)+1
                        token = 'token' + i
                        // console.log(typeof(token));
                        for(let key in userInfo) {
                            // console.log(typeof(key));
                            if(key===token) {
                               alert(` 
                                       city: '${userInfo[token].city}',
                                       money: '${userInfo[token].money}',
                                       sex: '${userInfo[token].sex}',
                                       userName: '${username}',
                                    `)
                                    return
                            }

                        }
                    }
                }
                let num = +prompt ('此账号不存在 1.注册2.退出')
                         if (num ===1) {
                            let userName = prompt('请输入用户名')
                            let password = prompt('请输入密码')
                            loginList.push({userName,password})
                            console.log(loginList);
                            alert('注册成功')
                         }
                         else if (num ===2) {
                          return
                         }
                         else {
                            alert('请输入正确的数字')
                         }
                      }
            }
            getLogin(loginList)
    </script>
</body>
</html>